#创造一个浏览器对象
import os.path
import sys
import datetime
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager


class Driver:
    driver = ""
    def __init__(self):
        # ChromeIns = ChromeDriverManager().install()
        # service = Service(r'C:\Users\mochi\.wdm\drivers\chromedriver\win64\128.0.6613.138\chromedriver-win32\chromedriver.exe/')
        options = webdriver.EdgeOptions()
        # options.service = service
        EdgeChromeIns = EdgeChromiumDriverManager().install()
        self.driver = webdriver.Edge(service = Service(EdgeChromeIns), options = options)
        # self.driver = webdriver.Chrome(options = options)
        self.driver.implicitly_wait(2)
    def getScreeShot(self):
        #创建屏幕截图
        #图片文件名称：时间戳
        #图片路径
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件夹是否已经存在，若不存在则创建文件夹
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)

        filename = sys._getframe().f_back.f_code.co_name + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)

BlogDriver = Driver()